/**
 * Created by wuye on 2017/12/11.
 */
$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/order/findAll',
        datatype: "json",
        colModel: [
            { label: 'ID', name: 'id', index: "id", width: 45, key: true },
            { label: '订单号', name: 'billno', width: 75 },
            { label: '用户名', name: 'username', width: 90 },
            { label: '手机号', name: 'userphone', width: 80 },
            { label: '来源类型', name: 'origin', width: 80,
                formatter: function(value, options, row) {
                    if (value === 0) {
                        return '<span class="label label-primary">本站</span>';
                    }
                    if (value === 1) {
                        return '<span class="label label-success">原创</span>';
                    }
                    if (value === 2) {
                        return '<span class="label label-info">趣阅</span>';
                    }
                    if (value === 3) {
                        return '<span class="label label-default">寒武</span>';
                    }
                } },
            { label: '来源', name: 'source', width: 80 },
            // { label: '金额', name: 'totalfee', width: 90},
            // { label: '书籍', name: 'bookid', width: 80},
            // { label: '章节', name: 'sectionid', width: 80},
        ],
        viewrecords: true,
        height: 385,
        rowNum: 10,
        rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth: true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.records",
            page: "page.current",
            total: "page.pages",
            records: "page.total"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
});

var setting = {
    data: {
        key: {
            url:"nourl"
        }
    }
};
var ztree;

var vm = new Vue({
    el:'#rrapp',
    data:{
        q:{
            orderusername: null
        },
        showList: true,
        title:null,
        order:{
            bookName:null,
            sectionName:null,
            totalfee:null
        },
        sels: [
            {value:"PAY_ALIWEB",week:"支付宝充值记录"},
            {value:"out",week:"书籍购买记录"},
        ],
        xels: [
            {value:"0",week:"本站"},
            {value:"1",week:"原创"},
            {value:"2",week:"趣阅"},
            {value:"3",week:"寒武"}
        ]
    },
    methods: {
        cateName: function () {
            vm.showList = true;
            vm.showDom = 'list'
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {
                    'payType': this.order.payType
                },
                page: page
            }).trigger("reloadGrid");
        },
        cateName1: function () {
            vm.showList = true;
            vm.showDom = 'list'
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {
                    'origin': this.order.origin
                },
                page: page
            }).trigger("reloadGrid");
        },
        findById: function () {
            var id = getSelectedRow();
            if(id == null){
                return ;
            }

            vm.showList = false;
            vm.title = "查看";
            vm.getOrder(id);
        },
        getOrder: function(id){
            $.get(baseURL + "sys/order/findById/"+id, function(r){
                vm.order = r.dto.tdOrder;
                vm.order.totalfee = (r.dto.tdOrder.totalfee)/100;
                vm.order.bookName = r.dto.tdBook.bookname;
                vm.order.sectionName = r.dto.tdSection.sectionname;
            });

        },
        query: function () {
            vm.reload();
        },
        reload: function () {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{
                postData:{'username': vm.q.orderusername},
                page:page
            }).trigger("reloadGrid");
        }
    }
});
